package com.woniuxy.mapper;

import com.woniuxy.entity.ComComment;
import com.woniuxy.entity.ComCommentLikes;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ComCommentMapper {
    //根据社区ID查询评论。
    List<ComComment> selectCommentsByCommunityId(Integer comId);

    //插入新评论
    @Insert("INSERT INTO com_comments (content, user_id, com_id, parent_id, likes_count)" +
            " VALUES (#{content}, #{userId}, #{comId},#{parentId}, #{likesCount})")
    void insertComment(ComComment comment);







    //对指定评论的点赞数进行原子性递增（+1）。
    @Update("UPDATE com_comments SET likes_count = likes_count + 1 WHERE comment_id = #{commentId}")
    void incrementLikesCount(@Param("commentId") Integer commentId);
    //对指定评论的点赞数进行原子性递减（-1）。
    @Update("UPDATE com_comments SET likes_count = likes_count - 1 WHERE comment_id = #{commentId}")
    void decrementLikesCount(@Param("commentId") Integer commentId);
    @Delete("Delete from com_comment_likes where comment_id = #{commentId} and user_id = #{userId}")
    void removeCommentLike(@Param("commentId") Integer commentId,@Param("userId") Integer userId);
    @Insert("INSERT INTO com_comment_likes (user_id, comment_id) VALUES ( #{userId}, #{commentId} )")
    void addCommentLike(@Param("commentId") Integer commentId, @Param("userId") Integer userId);
    @Select("SELECT * FROM com_comment_likes where user_id = #{userId} ")
    List<ComCommentLikes> getUserLikeComment(Integer userId);

    List<ComComment> getHotComments();
}
